package cn.IT.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.IT.dao.IApproveDAO;
import cn.IT.dao.IUserDAO;
import cn.IT.domain.Approve;
import cn.IT.domain.Topic;
import cn.IT.domain.User;

@Repository
@SuppressWarnings("all")
public class ApproveDAO extends BaseDAO<Approve> implements IApproveDAO{

	@Override
	public List<Approve> getAllUnapprovedByApprover(User user) {
		List<Approve> list = find("from Approve a where a.user = '" + user.getUserId() +"' and a.status = '待审核'");
		System.out.println(list.size());
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	@Override
	public List<Approve> getAllApproveByUser(User user) {
		List<Approve> list = find("from Approve a where a.topic.userByUserId = '" + user.getUserId() +"'");
		System.out.println(list.size());
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	@Override
	public List<Approve> getAllApprovedByApprover(User user) {
		List<Approve> list = find("from Approve a where a.user = '" + user.getUserId() +"' and a.status <> '待审核'");
		System.out.println(list.size());
		if(!list.isEmpty()){
			return list;
		}
		return null;
	}
	@Override
	public Approve getApprovedByTopic(Topic topic) {
		List<Approve> list = find("from Approve a where a.topic.topicId = '" + topic.getTopicId() +"' and a.status <> '驳回'");
		if(!list.isEmpty()){
			return (Approve)list.get(0);
		}
		return null;
		
	}
	
}
